package com.example.productdataserviceprovider.controller;

import com.example.productdataserviceprovider.dao.entity.Product;
import com.example.productdataserviceprovider.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class ProductController extends BaseController{
    @Autowired
    private ProductService productService;
    @Value("${spring.application.name}")
    private String applicationName;
    @Value("${spring.applcation.name2:applciation2}")
    private String applicationName2;
    @RequestMapping("/products")
    public List<Product> getAll(){
        List<Product> products=productService.listProducts();

        return products;
    }
    @RequestMapping("/products2")
    public String getAll2(){
        List<Product> products=productService.listProducts();
        StringBuilder builder=new StringBuilder("");
        for (Product vo : products) {
            builder.append(vo.toString()).append(",");
            logger.info(builder.toString());
        }
        return applicationName+":"+applicationName2+":"+products.toString();
    }
}
